/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.constant.enums;

import com.comac.ins.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 查询方式
 *
 * @author hxloongs
 * @date 2024-8-20
 */
@AllArgsConstructor
@Getter
public enum QueryModeEnum {
    EQ("eq", "精确查询"),
    LIKE("like", "模糊查询");
    private final String value;
    private final String desc;

    public static String getDescByValue(String value) {
        QueryModeEnum queryModeEnum = forValue(value);
        if (queryModeEnum == null) {
            return null;
        }
        return queryModeEnum.getDesc();
    }

    public static QueryModeEnum forValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (QueryModeEnum queryModeEnum : QueryModeEnum.values()) {
            if (queryModeEnum.getValue().equals(value)) {
                return queryModeEnum;
            }
        }
        return null;
    }

    public static QueryModeEnum forDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (QueryModeEnum queryModeEnum : QueryModeEnum.values()) {
            if (desc.equals(queryModeEnum.getDesc())) {
                return queryModeEnum;
            }
        }
        return null;
    }
}
